package net.georel.representation.categorisation.analysis;

import rcaller.RCaller;
import rcaller.RCode;

public class R_Analyses {
private static RCaller caller = new RCaller();
	
	private static void initRscriptExe(){
		caller.setRscriptExecutable("C:/Program Files/R/R-2.13.0/bin/Rscript");
		caller.cleanRCode();
	}
	
	public double getMean(double[] inputArray){
		initRscriptExe();
	    
	    RCode code = new RCode();
		double mean = 0.0;
		code.addDoubleArray("x", inputArray);   
		 code.addRCode("result <- mean(x)");
		 caller.setRCode(code);
		 caller.runAndReturnResult("result");
		    
		 double[] resultValues = caller.getParser().getAsDoubleArray("result");
		return resultValues[0];
	}
	
	public double getStandardDeviation(double[] inputArray){
		initRscriptExe();
	    
	    RCode code = new RCode();
		double mean = 0.0;
		code.addDoubleArray("x", inputArray);   
		 code.addRCode("result <- sd(x)");
		 caller.setRCode(code);
		 caller.runAndReturnResult("result");
		    
		 double[] resultValues = caller.getParser().getAsDoubleArray("result");
		return resultValues[0];
	}
}
